//
//  VisitorLoginView.swift
//  demo01新浪微博
//
//  Created by 杨兵 on 15/5/10.
//  Copyright (c) 2015年 bing. All rights reserved.
//

import UIKit

protocol VisitorLoginViewDelegate :NSObjectProtocol {
    // 点击注册
    func didregisterBtn(vsview:VisitorLoginView);
    // 点击登陆
    func didloginBtn(vsview:VisitorLoginView);
}

class VisitorLoginView: UIView {

    @IBOutlet weak var smallIconView: UIImageView!
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var messageLbl: UILabel!
    
    // 设置代理
    var delegate:VisitorLoginViewDelegate?
    
    
    /**
        设置元素,根据不同的信息显示不同样式,默认不是主页
    */
    func setupInfo(smallicon:String, msg:String, isHome:Bool = false) {
        
        // 主页就显示旋转图片
        if isHome {
            iconView.image = UIImage(named: smallicon)
            animationstart()
        } else {
            smallIconView.image = UIImage(named: smallicon)
            iconView.hidden = true
        }
        
        messageLbl.text = msg
    }
    private var animation = false
    
    func animationstart() {
        println("开启动画")
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.repeatCount = MAXFLOAT
        anim.toValue = 2 * M_PI
        anim.duration = 5.0
        
        // 指定了key,图层会对动画强引用
        smallIconView.layer.addAnimation(anim, forKey: "rotationanim")
    }
    
    func animationstop() {
        println("停止动画")
        smallIconView.layer.removeAllAnimations()
        iconView.hidden = true
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
    }

    
    @IBAction func register() {
        // 代理回调
        delegate?.didregisterBtn(self)
    }
    
    @IBAction func login(sender: AnyObject) {
        // 代理回调
        delegate?.didloginBtn(self)
    }

    
    
}
